package com.hinnotek.amoeba.ui.fragment

import androidx.fragment.app.viewModels
import com.hinnotek.amoeba.R
import com.hinnotek.amoeba.adapters.old.StatisticalRDProjectAdapter
import com.hinnotek.amoeba.bean.old.StatisticalRDProjectBean
import com.hinnotek.amoeba.databinding.FragmentStatisticalCustomerProjectBinding
import com.hinnotek.amoeba.dialog.CustomDialog
import com.hinnotek.amoeba.utilities.ToastUtils
import com.hinnotek.amoeba.viewmodels.ManageViewModel
import com.lee.common.base.BaseFragment
import com.lee.common.network.net.ObserverState
import com.xuexiang.xui.utils.WidgetUtils
import dagger.hilt.android.AndroidEntryPoint

/**
 *
 */
@AndroidEntryPoint
class FragmentStatisticalRDProject : BaseFragment<FragmentStatisticalCustomerProjectBinding>() {

    private var adapter: StatisticalRDProjectAdapter? = null
    private var orgId = 0

    private val viewModel by viewModels<ManageViewModel>()

    override fun getLayoutId(): Int {
       return R.layout.fragment_statistical_customer_project
    }

    override fun initData() {
        WidgetUtils.initRecyclerView(mBinding.rlv, 0)
        mBinding.rlv.adapter = StatisticalRDProjectAdapter().also { adapter = it }
        getAmibaProjectDetail(orgId)
    }


    fun setOrgId(orgId: Int) {
        this.orgId = orgId
    }

    /**
     * 获取统计详情中的研发项目
     */
    private fun getAmibaProjectDetail(orgId: Int) {
        val customDialog = CustomDialog(mContext, "正在加载...")
        customDialog.show()
        viewModel.getAmibaProjectDetail(orgId).observe(this,object : ObserverState<MutableList<StatisticalRDProjectBean>>(){
            override fun onDataChange(data: MutableList<StatisticalRDProjectBean>) {
                customDialog.dismiss()
                adapter?.setList(data)
                super.onDataChange(data)
            }

            override fun onError(msg: String?, code: Int) {
                customDialog.dismiss()
                ToastUtils.showShort(mContext, msg)
                super.onError(msg, code)
            }
        })
    }

}